package com.hqq.behaviour.feature_toggle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;

/**
 * App
 * Created by heqianqian on 2017/6/21.
 */
public class App {

    private static final Logger LOGGER = LoggerFactory.getLogger(App.class);

    public static void main(String[] args) {

        Properties properties = new Properties();
        properties.put("enhancedWelcome",true);
        Service service = new PropertiesFeatureToggleVersion(properties);
        String welcomeMessage = service.getWelcomeMessage(new User("Jamie No Code"));
        LOGGER.info(welcomeMessage);

        final Properties turnedOff = new Properties();
        turnedOff.put("enhancedWelcome", false);
        Service turnedOffService = new PropertiesFeatureToggleVersion(turnedOff);
        final String welcomeMessageturnedOff = turnedOffService.getWelcomeMessage(new User("Jamie No Code"));
        LOGGER.info(welcomeMessageturnedOff);

        Service service2 = new TieredFeatureToggleVersion();

        final User paidUser = new User("Jamie Coder");
        final User freeUser = new User("Alan Defect");

        UserGroup.addToPaidGroup(paidUser);
        UserGroup.addToFreeGroup(freeUser);

        final String welcomeMessagePaidUser = service2.getWelcomeMessage(paidUser);
        final String welcomeMessageFreeUser = service2.getWelcomeMessage(freeUser);
        LOGGER.info(welcomeMessageFreeUser);
        LOGGER.info(welcomeMessagePaidUser);
    }

}
